home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 526-550 / disk_534 / term / source.lzh / EmulationPanel.c < prev    next >
C/C++ Source or Header  |  1991-07-17  |  12KB  |  402 lines

  1. /* $Revision Header * Header built automatically - do not edit! *************
  2.  *
  3.  *    (C) Copyright 1990 by Olaf 'Olsen' Barthel & MXM
  4.  *
  5.  *    Name .....: EmulationPanel.c
  6.  *    Created ..: Thursday 21-Mar-91 20:19
  7.  *    Revision .: 0
  8.  *
  9.  *    Date            Author          Comment
  10.  *    =========       ========        ====================
  11.  *    21-Mar-91       Olsen           Created this file!
  12.  *
  13.  * $Revision Header ********************************************************/
  14.  
  15. #include "TermGlobal.h"
  16.  
  17. enum    {    GAD_SMOOTHSCROLL,GAD_WRAPCHARS,GAD_WRAPCURSOR,GAD_INSERTMODE,GAD_NEWLINE,
  18.         GAD_NUMKEYPAD,GAD_CURSORKEYS,GAD_FONTSCALE,GAD_USE,GAD_CANCEL };
  19.  
  20. #define WIDTH    367
  21. #define HEIGHT    128
  22.  
  23. STATIC STRPTR ControlMode[3] =
  24. {
  25.     (STRPTR)"Standard Mode",
  26.     (STRPTR)"Application Mode",
  27.     NULL
  28. };
  29.  
  30. STATIC STRPTR ScaleFontText[6] =
  31. {
  32.     (STRPTR)"Normal Scale",
  33.     (STRPTR)"Double Height (Top)",
  34.     (STRPTR)"Double Height (Bottom)",
  35.     (STRPTR)"Double Width",
  36.     (STRPTR)"Half Width",
  37.     NULL
  38. };
  39.  
  40. enum    {    MEN_SMOOTHSCROLL,MEN_WRAPCHARS,MEN_WRAPCURSOR,MEN_INSERTMODE,MEN_NEWLINE,
  41.         MEN_NUMKEYPAD,MEN_CURSORKEYS,MEN_FONTSCALE,MEN_USE,MEN_CANCEL,MEN_QUITPANEL };
  42.  
  43. STATIC struct NewMenu EmulationMenu[] =
  44. {
  45.     { NM_TITLE, "Project",             0 , 0, 0, (APTR)0},
  46.     {  NM_ITEM, "Smooth Scrolling",        "S", 0, 0, (APTR)MEN_SMOOTHSCROLL},
  47.     {  NM_ITEM, "Wrap Characters",        "C", 0, 0, (APTR)MEN_WRAPCHARS},
  48.     {  NM_ITEM, "Wrap Cursor Movements",    "M", 0, 0, (APTR)MEN_WRAPCURSOR},
  49.     {  NM_ITEM, "Insert Mode",        "I", 0, 0, (APTR)MEN_INSERTMODE},
  50.     {  NM_ITEM, "New-Line Mode",        "L", 0, 0, (APTR)MEN_NEWLINE},
  51.     {  NM_ITEM, "Numeric Keypad Mode",    "N", 0, 0, (APTR)MEN_NUMKEYPAD},
  52.     {  NM_ITEM, "Cursor Keys Mode",        "K", 0, 0, (APTR)MEN_CURSORKEYS},
  53.     {  NM_ITEM, "Font Scale",        "F", 0, 0, (APTR)MEN_FONTSCALE},
  54.     {  NM_ITEM, NM_BARLABEL,         0 , 0, 0, (APTR)0},
  55.     {  NM_ITEM, "Use",            "U", 0, 0, (APTR)MEN_USE},
  56.     {  NM_ITEM, "Cancel",            "C", 0, 0, (APTR)MEN_CANCEL},
  57.     {  NM_ITEM, NM_BARLABEL,         0 , 0, 0, (APTR)0},
  58.     {  NM_ITEM, "Quit",            "Q", 0, 0, (APTR)MEN_QUITPANEL},
  59.     { NM_END, 0,                 0 , 0, 0, (APTR)0}
  60. };
  61.  
  62. STATIC struct Gadget *
  63. CreateAllGadgets(struct Configuration *Config,struct Gadget *GadgetArray[],struct Gadget **GadgetList,APTR VisualInfo,UWORD TopEdge)
  64. {
  65.     struct Gadget        *Gadget;
  66.     struct NewGadget     NewGadget;
  67.     UWORD             Counter = 0;
  68.  
  69.     if(Gadget = CreateContext(GadgetList))
  70.     {
  71.         NewGadget . ng_Width        = 204;
  72.         NewGadget . ng_Height        = 12;
  73.         NewGadget . ng_GadgetText    = "_Smooth Scrolling";
  74.         NewGadget . ng_TextAttr        = &DefaultFont;
  75.         NewGadget . ng_VisualInfo    = VisualInfo;
  76.         NewGadget . ng_GadgetID        = Counter;
  77.         NewGadget . ng_Flags        = NG_HIGHLABEL;
  78.         NewGadget . ng_LeftEdge        = (strlen(NewGadget . ng_GadgetText) + 2) * 8 + 1;
  79.         NewGadget . ng_TopEdge        = 1 + TopEdge;
  80.  
  81.         GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  82.             GT_Underscore,    '_',
  83.             GTCB_Checked,    Config -> JumpScroll ^ TRUE,
  84.         TAG_DONE);
  85.  
  86.         NewGadget . ng_GadgetText    = "Wrap _Characters";
  87.         NewGadget . ng_GadgetID        = Counter;
  88.         NewGadget . ng_TopEdge        = Gadget -> TopEdge + Gadget -> Height + 1;
  89.  
  90.         GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  91.             GT_Underscore,    '_',
  92.             GTCB_Checked,    Config -> AutoWrap,
  93.         TAG_DONE);
  94.  
  95.         NewGadget . ng_GadgetText    = "Wrap Cursor _Moves";
  96.         NewGadget . ng_GadgetID        = Counter;
  97.         NewGadget . ng_TopEdge        = Gadget -> TopEdge + Gadget -> Height + 1;
  98.  
  99.         GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  100.             GT_Underscore,    '_',
  101.             GTCB_Checked,    Config -> CursorWrap,
  102.         TAG_DONE);
  103.  
  104.         NewGadget . ng_GadgetText    = "_Insert Mode";
  105.         NewGadget . ng_GadgetID        = Counter;
  106.         NewGadget . ng_TopEdge        = Gadget -> TopEdge + Gadget -> Height + 1;
  107.  
  108.         GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  109.             GT_Underscore,    '_',
  110.             GTCB_Checked,    Config -> InsertChar,
  111.         TAG_DONE);
  112.  
  113.         NewGadget . ng_GadgetText    = "New-_Line Mode";
  114.         NewGadget . ng_GadgetID        = Counter;
  115.         NewGadget . ng_TopEdge        = Gadget -> TopEdge + Gadget -> Height + 1;
  116.  
  117.         GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  118.             GT_Underscore,    '_',
  119.             GTCB_Checked,    Config -> NewLine,
  120.         TAG_DONE);
  121.  
  122.         NewGadget . ng_GadgetText    = "_Numeric Keypad";
  123.         NewGadget . ng_GadgetID        = Counter;
  124.         NewGadget . ng_TopEdge        = Gadget -> TopEdge + Gadget -> Height + 2;
  125.  
  126.         GadgetArray[Counter++] = Gadget = CreateGadget(CYCLE_KIND,Gadget,&NewGadget,
  127.             GT_Underscore,    '_',
  128.             GTCY_Labels,    ControlMode,
  129.             GTCY_Active,    Config -> NumApp,
  130.         TAG_DONE);
  131.  
  132.         NewGadget . ng_GadgetText    = "Cursor _Keys";
  133.         NewGadget . ng_GadgetID        = Counter;
  134.         NewGadget . ng_TopEdge        = Gadget -> TopEdge + Gadget -> Height + 1;
  135.  
  136.         GadgetArray[Counter++] = Gadget = CreateGadget(CYCLE_KIND,Gadget,&NewGadget,
  137.             GT_Underscore,    '_',
  138.             GTCY_Labels,    ControlMode,
  139.             GTCY_Active,    Config -> CursorApp,
  140.         TAG_DONE);
  141.  
  142.         NewGadget . ng_GadgetText    = "_Font Scale";
  143.         NewGadget . ng_GadgetID        = Counter;
  144.         NewGadget . ng_TopEdge        = Gadget -> TopEdge + Gadget -> Height + 1;
  145.  
  146.         GadgetArray[Counter++] = Gadget = CreateGadget(CYCLE_KIND,Gadget,&NewGadget,
  147.             GT_Underscore,    '_',
  148.             GTCY_Labels,    ScaleFontText,
  149.             GTCY_Active,    Config -> FontScale,
  150.         TAG_DONE);
  151.  
  152.         NewGadget . ng_Width        = 52;
  153.         NewGadget . ng_Height        = 12;
  154.         NewGadget . ng_GadgetText    = "_Use";
  155.         NewGadget . ng_GadgetID        = Counter;
  156.         NewGadget . ng_Flags        = 0;
  157.         NewGadget . ng_LeftEdge        = 10;
  158.         NewGadget . ng_TopEdge        = HEIGHT - 3 - NewGadget . ng_Height;
  159.  
  160.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  161.             GT_Underscore,    '_',
  162.         TAG_DONE);
  163.  
  164.         NewGadget . ng_GadgetText    = "_Cancel";
  165.         NewGadget . ng_GadgetID        = Counter;
  166.         NewGadget . ng_LeftEdge        = WIDTH - 10 - NewGadget . ng_Width;
  167.  
  168.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  169.             GT_Underscore,    '_',
  170.         TAG_DONE);
  171.     }
  172.  
  173.     return(Gadget);
  174. }
  175.  
  176. VOID
  177. EmulationPanel(struct Configuration *Config)
  178. {
  179.     struct Window    *PanelWindow;
  180.     struct Menu    *PanelMenu;
  181.     struct Gadget    *GadgetList;
  182.     struct Gadget    *GadgetArray[GAD_CANCEL + 1];
  183.  
  184.     ClearCursor();
  185.  
  186.     CopyMem(Config,&PrivateConfig,sizeof(struct Configuration));
  187.  
  188.     if(CreateAllGadgets(Config,&GadgetArray[0],&GadgetList,VisualInfo,Screen -> WBorTop + Screen -> Font -> ta_YSize + 1))
  189.     {
  190.         if(PanelMenu = CreateMenus(EmulationMenu,
  191.             GTMN_FrontPen, 0,
  192.         TAG_DONE))
  193.         {
  194.             if(LayoutMenus(PanelMenu,VisualInfo,
  195.                 GTMN_TextAttr,&DefaultFont,
  196.             TAG_DONE))
  197.             {
  198.                 if(PanelWindow = OpenWindowTags(NULL,
  199.                     WA_Left,    (Screen -> Width - WIDTH) >> 1,
  200.                     WA_Top,        (Screen -> Height - HEIGHT) >> 1,
  201.                     WA_Width,    WIDTH,
  202.                     WA_Height,    HEIGHT,
  203.                     WA_Activate,    TRUE,
  204.                     WA_DragBar,    TRUE,
  205.                     WA_DepthGadget,    TRUE,
  206.                     WA_RMBTrap,    TRUE,
  207.                     WA_DepthGadget,    TRUE,
  208.                     WA_CloseGadget,    TRUE,
  209.                     WA_CustomScreen,Screen,
  210.                     WA_IDCMP,    IDCMP_GADGETDOWN | IDCMP_ACTIVEWINDOW | IDCMP_CLOSEWINDOW | SLIDERIDCMP | CHECKBOXIDCMP | LISTVIEWIDCMP | IDCMP_MENUPICK | IDCMP_RAWKEY,
  211.                     WA_Title,    "Emulation Preferences",
  212.                 TAG_DONE))
  213.                 {
  214.                     struct IntuiMessage    *Massage;
  215.                     ULONG             Class,Code;
  216.                     struct Gadget        *Gadget;
  217.                     BYTE             Terminated = FALSE;
  218.  
  219.                     PushWindow(PanelWindow);
  220.  
  221.                     AddGList(PanelWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
  222.                     RefreshGList(GadgetList,PanelWindow,NULL,(UWORD)-1);
  223.                     GT_RefreshWindow(PanelWindow,NULL);
  224.  
  225.                     SetMenuStrip(PanelWindow,PanelMenu);
  226.  
  227.                     PanelWindow -> Flags &= ~WFLG_RMBTRAP;
  228.  
  229.                     while(!Terminated)
  230.                     {
  231.                         WaitPort(PanelWindow -> UserPort);
  232.  
  233.                         while(!Terminated && (Massage = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort)))
  234.                         {
  235.                             Class    = Massage -> Class;
  236.                             Code    = Massage -> Code;
  237.                             Gadget    = (struct Gadget *)Massage -> IAddress;
  238.  
  239.                             GT_ReplyIMsg(Massage);
  240.  
  241.                             if(Class == IDCMP_MENUPICK)
  242.                             {
  243.                                 struct MenuItem *MenuItem;
  244.  
  245.                                 while(Code != MENUNULL)
  246.                                 {
  247.                                     MenuItem = ItemAddress(PanelMenu,Code);
  248.  
  249.                                     switch((ULONG)MENU_USERDATA(MenuItem))
  250.                                     {
  251.                                         case MEN_QUITPANEL:    Class = IDCMP_CLOSEWINDOW;
  252.                                                     break;
  253.  
  254.                                         case MEN_USE:        Class = IDCMP_GADGETUP;
  255.                                                     Gadget = GadgetArray[GAD_USE];
  256.                                                     break;
  257.  
  258.                                         case MEN_CANCEL:    Class = IDCMP_GADGETUP;
  259.                                                     Gadget = GadgetArray[GAD_CANCEL];
  260.                                                     break;
  261.  
  262.                                         case MEN_SMOOTHSCROLL:    GT_SetGadgetAttrs(GadgetArray[GAD_SMOOTHSCROLL],PanelWindow,NULL,
  263.                                                         GTCB_Checked,GadgetArray[GAD_SMOOTHSCROLL] -> Flags & GFLG_SELECTED ? FALSE : TRUE,
  264.                                                     TAG_DONE);
  265.  
  266.                                                     break;
  267.  
  268.                                         case MEN_WRAPCHARS:    GT_SetGadgetAttrs(GadgetArray[GAD_WRAPCHARS],PanelWindow,NULL,
  269.                                                         GTCB_Checked,GadgetArray[GAD_WRAPCHARS] -> Flags & GFLG_SELECTED ? FALSE : TRUE,
  270.                                                     TAG_DONE);
  271.  
  272.                                                     break;
  273.  
  274.                                         case MEN_WRAPCURSOR:    GT_SetGadgetAttrs(GadgetArray[GAD_WRAPCURSOR],PanelWindow,NULL,
  275.                                                         GTCB_Checked,GadgetArray[GAD_WRAPCURSOR] -> Flags & GFLG_SELECTED ? FALSE : TRUE,
  276.                                                     TAG_DONE);
  277.  
  278.                                                     break;
  279.  
  280.                                         case MEN_NEWLINE:    GT_SetGadgetAttrs(GadgetArray[GAD_NEWLINE],PanelWindow,NULL,
  281.                                                         GTCB_Checked,GadgetArray[GAD_NEWLINE] -> Flags & GFLG_SELECTED ? FALSE : TRUE,
  282.                                                     TAG_DONE);
  283.  
  284.                                                     break;
  285.  
  286.                                         case MEN_INSERTMODE:    GT_SetGadgetAttrs(GadgetArray[GAD_INSERTMODE],PanelWindow,NULL,
  287.                                                         GTCB_Checked,GadgetArray[GAD_INSERTMODE] -> Flags & GFLG_SELECTED ? FALSE : TRUE,
  288.                                                     TAG_DONE);
  289.  
  290.                                                     break;
  291.  
  292.                                         case MEN_NUMKEYPAD:    Config -> NumApp ^= TRUE;
  293.  
  294.                                                     GT_SetGadgetAttrs(GadgetArray[GAD_NUMKEYPAD],PanelWindow,NULL,
  295.                                                         GTCY_Active,Config -> NumApp,
  296.                                                     TAG_DONE);
  297.  
  298.                                                     break;
  299.  
  300.                                         case MEN_CURSORKEYS:    Config -> CursorApp ^= TRUE;
  301.  
  302.                                                     GT_SetGadgetAttrs(GadgetArray[GAD_CURSORKEYS],PanelWindow,NULL,
  303.                                                         GTCY_Active,Config -> CursorApp,
  304.                                                     TAG_DONE);
  305.  
  306.                                                     break;
  307.  
  308.                                         case MEN_FONTSCALE:    if(Config -> FontScale == SCALE_HALF)
  309.                                                         Config -> FontScale = SCALE_NORMAL;
  310.                                                     else
  311.                                                         Config -> FontScale++;
  312.  
  313.                                                     GT_SetGadgetAttrs(GadgetArray[GAD_FONTSCALE],PanelWindow,NULL,
  314.                                                         GTCY_Active,Config -> FontScale,
  315.                                                     TAG_DONE);
  316.  
  317.                                                     break;
  318.  
  319.                                         default:        break;
  320.                                     }
  321.  
  322.                                     Code = MenuItem -> NextSelect;
  323.                                 }
  324.                             }
  325.  
  326.                             if(Class == IDCMP_CLOSEWINDOW)
  327.                                 Terminated = TRUE;
  328.  
  329. GadCheck:                        if(Class == IDCMP_GADGETUP)
  330.                             {
  331.                                 switch(Gadget -> GadgetID)
  332.                                 {
  333.                                     case GAD_USE:        Terminated = TRUE;
  334.  
  335.                                                 Config -> JumpScroll = (GadgetArray[GAD_SMOOTHSCROLL] -> Flags & GFLG_SELECTED) ? FALSE : TRUE;
  336.                                                 Config -> AutoWrap = GadgetArray[GAD_WRAPCHARS] -> Flags & GFLG_SELECTED;
  337.                                                 Config -> CursorWrap = GadgetArray[GAD_WRAPCURSOR] -> Flags & GFLG_SELECTED;
  338.                                                 Config -> InsertChar = GadgetArray[GAD_INSERTMODE] -> Flags & GFLG_SELECTED;
  339.                                                 Config -> NewLine = GadgetArray[GAD_NEWLINE] -> Flags & GFLG_SELECTED;
  340.  
  341.                                                 break;
  342.  
  343.                                     case GAD_CANCEL:    Terminated = TRUE;
  344.  
  345.                                                 CopyMem(&PrivateConfig,Config,sizeof(struct Configuration));
  346.  
  347.                                                 break;
  348.  
  349.                                     case GAD_NUMKEYPAD:    Config -> NumApp = Code;
  350.                                                 break;
  351.  
  352.                                     case GAD_CURSORKEYS:    Config -> CursorApp = Code;
  353.                                                 break;
  354.  
  355.                                     case GAD_FONTSCALE:    Config -> FontScale = Code;
  356.                                                 break;
  357.  
  358.                                     default:        break;
  359.                                 }
  360.                             }
  361.                         }
  362.                     }
  363.  
  364.                     PanelWindow -> Flags |= WFLG_RMBTRAP;
  365.  
  366.                     ClearMenuStrip(PanelWindow);
  367.  
  368.                     RemoveGList(PanelWindow,GadgetList,(UWORD)-1);
  369.  
  370.                     PopWindow();
  371.  
  372.                     CloseWindow(PanelWindow);
  373.                 }
  374.             }
  375.  
  376.             FreeMenus(PanelMenu);
  377.         }
  378.  
  379.         FreeGadgets(GadgetList);
  380.     }
  381.  
  382.     if(PrivateConfig . FontScale == SCALE_HALF && Config -> FontScale != SCALE_HALF)
  383.     {
  384.         CursorX >>= 1;
  385.  
  386.         if(Config -> EightyColumns)
  387.             LastColumn = 79;
  388.         else
  389.             LastColumn = (Window -> Width >> 3) - 1;
  390.     }
  391.  
  392.     if(PrivateConfig . FontScale != SCALE_HALF && Config -> FontScale == SCALE_HALF)
  393.     {
  394.         if(Config -> EightyColumns)
  395.             LastColumn = 131;
  396.         else
  397.             LastColumn = (Window -> Width >> 2) - 1;
  398.     }
  399.  
  400.     SetCursor();
  401. }
  402.